﻿using System;
using System.ComponentModel;

namespace NTTDATA.BEENChina.ResultCertification.PropertyGridUtil.CustomObject
{
    public class ElementSettingTypeConverter : ExpandableObjectConverter
    {
        public override object ConvertTo(ITypeDescriptorContext context,
            System.Globalization.CultureInfo culture, object value, Type destinationType)
        {   
            if (destinationType == typeof(string))
            {
                ElementSetting setting = (ElementSetting)value;
                return setting.Startindex + ";" + setting.Length + ";[" + string.Join(",", setting.Values) + "]";
            }
            return base.ConvertTo(context, culture, value, destinationType);
        }

        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            return TypeDescriptor.GetProperties(typeof(ElementSetting), attributes).Sort(new string[] { "Starindex", "Length" ,"Values"});
        }

        public override bool GetPropertiesSupported(ITypeDescriptorContext context)
        {
            return true;
        }
    }
}
